package router

import (
	"github.com/gin-gonic/gin"
	"zk1/api/client"
	"zk1/api/enit"
	"zk1/common/proto/goods"
)

func Create(c *gin.Context) {
	var data enit.Goods
	if err := c.ShouldBind(&data); err != nil {
		c.JSON(500, gin.H{
			"code": 500,
			"msg":  "参数错误",
		})
		return
	}
	_, err := client.Create(c, &goods.CreateRequest{
		GoodsDescription: data.GoodsDescription,
		GoodsCode:        int64(data.GoodsCode),
		GoodsPrice:       int64(data.GoodsPrice),
		SalesVolume:      int64(data.SalesVolume),
		Classification:   int64(data.Classification),
		Status:           int64(data.Status),
	})
	if err != nil {
		c.JSON(500, gin.H{
			"code": 500,
			"msg":  "商品发布失败",
		})
		return
	}
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "商品发布成功",
	})
}

func List(c *gin.Context) {
	var data enit.Goods
	if err := c.ShouldBind(&data); err != nil {
		c.JSON(500, gin.H{
			"code": 500,
			"msg":  "参数错误",
		})
		return
	}
	list, err := client.List(c, &goods.ListRequest{})
	if err != nil {
		c.JSON(500, gin.H{
			"code": 500,
			"msg":  "商品列表展示失败",
		})
		return
	}
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "商品列表展示成功",
		"data": list,
	})
}
